/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2019
 */

package net.dreamlu.db.qo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Order;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.criterion.MatchMode;
import org.springframework.data.jpa.domain.Specification;
import net.dreamlu.db.po.*;
/**
 *
 * @author lambert.wang email:lambert.wang(a)crediteyes.com
 * @version 1.0
 * @since 1.0
 */
public class AdminRoleQuery extends AdminRole implements Serializable {
    private static final long serialVersionUID = 3148176768559230877L;
    

	/** 主键id */
	private java.lang.Integer id;	
	private java.lang.Integer notEqId;	
	/** 用户id */
	private java.lang.Integer adminId;	
	private java.lang.Integer notEqAdminId;	
	/** 角色id */
	private java.lang.Integer roleId;	
	private java.lang.Integer notEqRoleId;	
	
	/*********** 系统属性，自动赋值 *********/
	private boolean isId;
	private boolean isNotEqId;
	private boolean isAdminId;
	private boolean isNotEqAdminId;
	private boolean isRoleId;
	private boolean isNotEqRoleId;
	private java.lang.Integer ltCriterionId;
	public void setLtId(java.lang.Integer id){
		ltCriterionId = id;
	}
	public java.lang.Integer getLtId(){
		return ltCriterionId;
	}
	private java.lang.Integer leCriterionId;
	public void setLeId(java.lang.Integer id){
		leCriterionId = id;
	}
	public java.lang.Integer getLeId(){
		return leCriterionId;
	}
	private java.lang.Integer gtCriterionId;
	public void setGtId(java.lang.Integer id){
		gtCriterionId = id;
	}
	public java.lang.Integer getGtId(){
		return gtCriterionId;
	}
	private java.lang.Integer geCriterionId;
	public void setGeId(java.lang.Integer id){
		geCriterionId = id;
	}
	public java.lang.Integer getGeId(){
		return geCriterionId;
	}
	public java.lang.Integer getId() {
		return this.id;
	}
	
	public void setId(java.lang.Integer value) {		
		this.id = value;
		this.isId = true;
	}
	public boolean hasId() {
		return this.isId;
	}
	public java.lang.Integer getNotEqId() {
		return this.notEqId;
	}
	public void setNotEqId(java.lang.Integer id) {
		this.notEqId = id;
		this.isNotEqId = true;
	}
	public boolean hasNotEqId() {
		return this.isNotEqId;
	}
	// IN or notIN
	private List<java.lang.Integer>	inCriterionId;
	private List<java.lang.Integer>	notInCriterionId;
	public void setInId(boolean isIn,List<java.lang.Integer> ids){
		if(isIn){
			inCriterionId = ids;
		}else{
			notInCriterionId = ids;
		}
	}
	public List<java.lang.Integer> getInId() {
		return inCriterionId;
	}
	public List<java.lang.Integer> getNotInId() {
		return notInCriterionId;
	}
	
	//Null or NotNull
	private Boolean nullCriterionId;
	public void setNullId(boolean isNull){
			nullCriterionId = isNull;
	}
	public Boolean getNullId(){
		return nullCriterionId;
	} 
	
	private java.lang.Integer ltCriterionAdminId;
	public void setLtAdminId(java.lang.Integer adminId){
		ltCriterionAdminId = adminId;
	}
	public java.lang.Integer getLtAdminId(){
		return ltCriterionAdminId;
	}
	private java.lang.Integer leCriterionAdminId;
	public void setLeAdminId(java.lang.Integer adminId){
		leCriterionAdminId = adminId;
	}
	public java.lang.Integer getLeAdminId(){
		return leCriterionAdminId;
	}
	private java.lang.Integer gtCriterionAdminId;
	public void setGtAdminId(java.lang.Integer adminId){
		gtCriterionAdminId = adminId;
	}
	public java.lang.Integer getGtAdminId(){
		return gtCriterionAdminId;
	}
	private java.lang.Integer geCriterionAdminId;
	public void setGeAdminId(java.lang.Integer adminId){
		geCriterionAdminId = adminId;
	}
	public java.lang.Integer getGeAdminId(){
		return geCriterionAdminId;
	}
	public java.lang.Integer getAdminId() {
		return this.adminId;
	}
	
	public void setAdminId(java.lang.Integer value) {		
		this.adminId = value;
		this.isAdminId = true;
	}
	public boolean hasAdminId() {
		return this.isAdminId;
	}
	public java.lang.Integer getNotEqAdminId() {
		return this.notEqAdminId;
	}
	public void setNotEqAdminId(java.lang.Integer adminId) {
		this.notEqAdminId = adminId;
		this.isNotEqAdminId = true;
	}
	public boolean hasNotEqAdminId() {
		return this.isNotEqAdminId;
	}
	// IN or notIN
	private List<java.lang.Integer>	inCriterionAdminId;
	private List<java.lang.Integer>	notInCriterionAdminId;
	public void setInAdminId(boolean isIn,List<java.lang.Integer> adminIds){
		if(isIn){
			inCriterionAdminId = adminIds;
		}else{
			notInCriterionAdminId = adminIds;
		}
	}
	public List<java.lang.Integer> getInAdminId() {
		return inCriterionAdminId;
	}
	public List<java.lang.Integer> getNotInAdminId() {
		return notInCriterionAdminId;
	}
	
	//Null or NotNull
	private Boolean nullCriterionAdminId;
	public void setNullAdminId(boolean isNull){
			nullCriterionAdminId = isNull;
	}
	public Boolean getNullAdminId(){
		return nullCriterionAdminId;
	} 
	
	private java.lang.Integer ltCriterionRoleId;
	public void setLtRoleId(java.lang.Integer roleId){
		ltCriterionRoleId = roleId;
	}
	public java.lang.Integer getLtRoleId(){
		return ltCriterionRoleId;
	}
	private java.lang.Integer leCriterionRoleId;
	public void setLeRoleId(java.lang.Integer roleId){
		leCriterionRoleId = roleId;
	}
	public java.lang.Integer getLeRoleId(){
		return leCriterionRoleId;
	}
	private java.lang.Integer gtCriterionRoleId;
	public void setGtRoleId(java.lang.Integer roleId){
		gtCriterionRoleId = roleId;
	}
	public java.lang.Integer getGtRoleId(){
		return gtCriterionRoleId;
	}
	private java.lang.Integer geCriterionRoleId;
	public void setGeRoleId(java.lang.Integer roleId){
		geCriterionRoleId = roleId;
	}
	public java.lang.Integer getGeRoleId(){
		return geCriterionRoleId;
	}
	public java.lang.Integer getRoleId() {
		return this.roleId;
	}
	
	public void setRoleId(java.lang.Integer value) {		
		this.roleId = value;
		this.isRoleId = true;
	}
	public boolean hasRoleId() {
		return this.isRoleId;
	}
	public java.lang.Integer getNotEqRoleId() {
		return this.notEqRoleId;
	}
	public void setNotEqRoleId(java.lang.Integer roleId) {
		this.notEqRoleId = roleId;
		this.isNotEqRoleId = true;
	}
	public boolean hasNotEqRoleId() {
		return this.isNotEqRoleId;
	}
	// IN or notIN
	private List<java.lang.Integer>	inCriterionRoleId;
	private List<java.lang.Integer>	notInCriterionRoleId;
	public void setInRoleId(boolean isIn,List<java.lang.Integer> roleIds){
		if(isIn){
			inCriterionRoleId = roleIds;
		}else{
			notInCriterionRoleId = roleIds;
		}
	}
	public List<java.lang.Integer> getInRoleId() {
		return inCriterionRoleId;
	}
	public List<java.lang.Integer> getNotInRoleId() {
		return notInCriterionRoleId;
	}
	
	//Null or NotNull
	private Boolean nullCriterionRoleId;
	public void setNullRoleId(boolean isNull){
			nullCriterionRoleId = isNull;
	}
	public Boolean getNullRoleId(){
		return nullCriterionRoleId;
	} 
	
	private List<String> listOrderAsc = new ArrayList<>();
	private List<String> listOrderDesc = new ArrayList<>();

	public void setOrderAsc(String fdName) {
		listOrderAsc.add(fdName);
	}

	public void setOrderDec(String fdName) {
		listOrderDesc.add(fdName);
	}

	public List<String> getOrderAscList() {
		return listOrderAsc;
	}

	public List<String> getOrderDecList() {
		return listOrderDesc;
	}
	
	
	/**
	 * 获取查询条件
	 */
	public Specification<AdminRole> createSpecification() {
		Specification<AdminRole> example = (root, query, criteriaBuilder) -> {
			List<Order> orders = new ArrayList<>();
			for (String asc : this.getOrderAscList()) {
				orders.add(criteriaBuilder.asc(root.get(asc)));
			}
			for (String desc : this.getOrderDecList()) {
				orders.add(criteriaBuilder.desc(root.get(desc)));
			}
			query.orderBy(orders);
			List<Predicate> predicates = createQuery(root, this, criteriaBuilder);
			hookQuery(root, criteriaBuilder,predicates);
			return query.where(predicates.toArray(new Predicate[predicates.size()])).getRestriction();
		};
		return example;
	}
	/**
	 * <p>
	 * <p>自定义的方法时候实现此方法即可(内部类方式使用即可)
	 * <p>使用方法: predicates.add(criteriaBuilder.equal(root.get("biaoqian").as(String.class), "value"));
	 * @param root
	 * @param query
	 * @param criteriaBuilder
	 * @param predicates
	 */
	public void hookQuery(Root<AdminRole> root, CriteriaBuilder criteriaBuilder,List<Predicate> predicates) {}
	/**
	 * 组装query对象
	 * 
	 * @param root
	 * @param AdminRoleQuery
	 * @param criteriaBuilder
	 * @return
	 */
	private List<Predicate> createQuery(Root<AdminRole> root, AdminRoleQuery query, CriteriaBuilder criteriaBuilder) {
		List<Predicate> predicates = new ArrayList<Predicate>();
		/**
		 * idExpression
		 */
		Expression<java.lang.Integer> idExpression = root.get(AdminRole.PROP_ID).as(java.lang.Integer.class);
		if (query.hasId()) {
			java.lang.Integer value = query.getId();
			if( value != null){
				predicates.add(criteriaBuilder.equal(idExpression, value));					
			}
		}
		if (query.hasNotEqId()) {
			java.lang.Integer value = query.getNotEqId();
			predicates.add(criteriaBuilder.notEqual(idExpression, value));
		}
		
		if(query.getLeId()!=null){
			predicates.add(criteriaBuilder.le(idExpression, query.getLeId()));
		}
		if(query.getGeId()!=null){
			predicates.add(criteriaBuilder.ge(idExpression, query.getGeId()));
		}
		if(query.getLtId()!=null){
			predicates.add(criteriaBuilder.lt(idExpression, query.getLtId()));
		}
		if(query.getGtId()!=null){
			predicates.add(criteriaBuilder.gt(idExpression, query.getGtId()));
		}
		
		if (query.getInId() != null) {
			predicates.add(idExpression.in(query.getInId()));
		}
		if (query.getNotInId() != null) {
			predicates.add(criteriaBuilder.not(idExpression.in(query.getInId())));
		}
		if (query.getNullId() != null) {
			if (query.getNullId()) {
				predicates.add(criteriaBuilder.isNull(idExpression));
			} else {
				predicates.add(criteriaBuilder.isNotNull(idExpression));
			}
		}
		/**
		 * adminIdExpression
		 */
		Expression<java.lang.Integer> adminIdExpression = root.get(AdminRole.PROP_ADMIN_ID).as(java.lang.Integer.class);
		if (query.hasAdminId()) {
			java.lang.Integer value = query.getAdminId();
			if( value != null){
				predicates.add(criteriaBuilder.equal(adminIdExpression, value));					
			}
		}
		if (query.hasNotEqAdminId()) {
			java.lang.Integer value = query.getNotEqAdminId();
			predicates.add(criteriaBuilder.notEqual(adminIdExpression, value));
		}
		
		if(query.getLeAdminId()!=null){
			predicates.add(criteriaBuilder.le(adminIdExpression, query.getLeAdminId()));
		}
		if(query.getGeAdminId()!=null){
			predicates.add(criteriaBuilder.ge(adminIdExpression, query.getGeAdminId()));
		}
		if(query.getLtAdminId()!=null){
			predicates.add(criteriaBuilder.lt(adminIdExpression, query.getLtAdminId()));
		}
		if(query.getGtAdminId()!=null){
			predicates.add(criteriaBuilder.gt(adminIdExpression, query.getGtAdminId()));
		}
		
		if (query.getInAdminId() != null) {
			predicates.add(adminIdExpression.in(query.getInAdminId()));
		}
		if (query.getNotInAdminId() != null) {
			predicates.add(criteriaBuilder.not(adminIdExpression.in(query.getInAdminId())));
		}
		if (query.getNullAdminId() != null) {
			if (query.getNullAdminId()) {
				predicates.add(criteriaBuilder.isNull(adminIdExpression));
			} else {
				predicates.add(criteriaBuilder.isNotNull(adminIdExpression));
			}
		}
		/**
		 * roleIdExpression
		 */
		Expression<java.lang.Integer> roleIdExpression = root.get(AdminRole.PROP_ROLE_ID).as(java.lang.Integer.class);
		if (query.hasRoleId()) {
			java.lang.Integer value = query.getRoleId();
			if( value != null){
				predicates.add(criteriaBuilder.equal(roleIdExpression, value));					
			}
		}
		if (query.hasNotEqRoleId()) {
			java.lang.Integer value = query.getNotEqRoleId();
			predicates.add(criteriaBuilder.notEqual(roleIdExpression, value));
		}
		
		if(query.getLeRoleId()!=null){
			predicates.add(criteriaBuilder.le(roleIdExpression, query.getLeRoleId()));
		}
		if(query.getGeRoleId()!=null){
			predicates.add(criteriaBuilder.ge(roleIdExpression, query.getGeRoleId()));
		}
		if(query.getLtRoleId()!=null){
			predicates.add(criteriaBuilder.lt(roleIdExpression, query.getLtRoleId()));
		}
		if(query.getGtRoleId()!=null){
			predicates.add(criteriaBuilder.gt(roleIdExpression, query.getGtRoleId()));
		}
		
		if (query.getInRoleId() != null) {
			predicates.add(roleIdExpression.in(query.getInRoleId()));
		}
		if (query.getNotInRoleId() != null) {
			predicates.add(criteriaBuilder.not(roleIdExpression.in(query.getInRoleId())));
		}
		if (query.getNullRoleId() != null) {
			if (query.getNullRoleId()) {
				predicates.add(criteriaBuilder.isNull(roleIdExpression));
			} else {
				predicates.add(criteriaBuilder.isNotNull(roleIdExpression));
			}
		}
		return predicates;
	}
	public String toString() {
		return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE);
	}
	
}

